<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<input type="button" id="b1" name="b1" value="测试"/>
<div id="id">


</div>
</body>
<script type="text/javascript">
    //a 创建XmlHttpRequest对象 固定写法
    function createXmlHttpRequest(){
        var xmlHttp;
        try{    //Firefox, Opera 8.0+, Safari
            xmlHttp=new XMLHttpRequest();
        }catch (e){
            try{    //Internet Explorer
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            }catch (e){
                try{
                    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                }catch (e){}
            }
        }
        return xmlHttp;
    }
    var xhr = createXmlHttpRequest();
    // b 注册状态变化的事件处理
            xhr.onreadystatechange = function(){
                if(xhr.readyState==4){
                    if(xhr.status==200||xhr.status==304){
                        //服务器返回的数据
                        var data = xhr.responseText;
                        document.getElementById("id").innerHTML=data;
                    }
                }
            }
    //c  初始化对象
        xhr.open("POST","/servlet/servlet?time="+new  Date().getTime());
    //d 向服务器发送数据
        xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        xhr.send("username=admin&password=123");
</script>
</html>